<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /><!-- 控制浏览器文件模式为IE8 -->
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="js/artDialog/skins/default.css" rel="stylesheet" type="text/css" />
<link href="css/sele.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/artDialog/artDialog.js?skin=blue"></script>
<script src="js/artDialog/plugins/iframeTools.js"></script>
<script type="text/javascript" src="js/operamasks-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/elegant/om-all.css" />
<title>新增功能項頁面</title>
<script> 
(function (config) {
    config['lock'] = true;
    config['fixed'] = true;
    config['okVal'] = 'Ok';
    config['cancelVal'] = 'Cancel';
})(art.dialog.defaults);
</script>
<script type="text/javascript">
$(function(){
	function showDialog(msg){
		art.dialog({
			id:'art1',
			title:'溫馨提示',
			content :msg,
			width:'27.8%',
			height:'11.6%',
			time:1.5
		});
	}
	var isEx='${isEx}';
	if(isEx=="fail"){
		art.dialog.tips('該功能已存在！', 1.5);
	}else if(isEx=="success") {
		document.getElementById("functionName").value="${functionName}";
	}
	var isSuccess = '${isSuccess}';
	if(isSuccess=="success")
	{
		$.omMessageBox.alert({
	           content:'新增功能成功！',
	           onClose:function(v){
	        	   document.location.href = './adminFunction.do?action=list';
	           }
	       });
	}
	else if(isSuccess=="fail")
	{
		$.omMessageBox.alert({
	           content:'新增功能失敗！',
	           onClose:function(v){
	           }
	       });
	}
	$("#setParentId").click(function(){
		document.getElementById("parentId").value = "00";
		document.getElementById("parentFunction").value = "名稱：無  —— 編碼：00";
	});
	
	$("#chooseParentId").click(function(){
		art.dialog.open('./adminFunction.do?action=allList', {
		    title: '選擇上一級功能項',
		    height: '90%',
		    width: '90%',
		    okVal:'確定',
		    ok: function () {
		    	var iframe = this.iframe.contentWindow;
		    	if (!iframe.document.body) {
		        	alert('iframe還沒加載完畢呢')
		        	return false;
		        };
		        var functionId = iframe.j(":radio:checked")[0].id;
		        var functionCode = iframe.j(":radio:checked")[0].value;
		        document.getElementById("parentId").value = functionId;
				document.getElementById("parentFunction").value = functionCode;
		    },
		    cancelVal:'取消',
		    cancel: true
		});
	});
	
	$("#save").click(function(){
		var functionName = document.getElementById("functionName").value;
		var functionCode = document.getElementById("functionCode").value;
		
		var flag=true;
		
		if(functionName==null || functionName=="" ||!(/\S/.test(functionName)))
		{
			art.dialog.tips('功能項名稱不能為空！', 1.5);
			document.getElementById("functionName").focus();
			flag=false;
			return;
		}
		if(functionCode == null || functionCode=="" ||!(/\S/.test(functionCode))){
			art.dialog.tips('功能項編碼不能为空！', 1.5);
			document.getElementById("functionCode").focus();
			flag=false;
			return; 
		}else if(functionCode.length > 6){
			art.dialog.tips('編碼長度不能超過6位！',1.5);
			document.getElementById("functionCode").focus();
			flag=false;
			return;
		}
		if(flag==true)
		{
			document.forms[0].submit();
		}
	});
});
	
</script>
</head>
<body>
	<div class="place">
	    <span>位置：</span>
	    <ul class="placeul">
	    <li>首頁</li>
		<li>系統管理</li>
	    <li><a href="#" onclick="javascript:window.location.href='./adminFunction.do?action=list'"> 功能項管理</a></li>
		<li>新增功能項</li>
	    </ul>
    </div>
    <div class="formbody">
	    <div class="formtitle"><span>基本信息</span></div>
	    <form id="form1" action="./adminFunction.do?action=add" method="post" name="ap_add"  >
	    <ul class="forminfo">
		    <li><label>功能項名稱：</label><input id="functionName" name="functionName" autocomplete="off" type="text" class="dfinput" /><i>*必填</i></li>
		    <li>
		    	<label>上一級功能項：</label>
		    	<input id="parentId" name="parentId" type="hidden" class="dfinput"/>
		    	<input id="parentFunction" type="text" class="dfinput" readonly="readonly"/>
		    	<input id="chooseParentId" type="button" class="btn" value="選擇上一級功能項"/>
		    	<input id="setParentId" type="button" class="btn" value="設置為根功能項"/>
		    	<%-- <div class="vocation">
			    	<select id="parentId" name="parentId" class="form-control" style="width:30%">
			    		<option value="00">名称：无  —— 编码：00</option>
	            	<c:forEach var="list" items="${functionList }">
	            		<option value="${list.functionId }">名称：${list.functionName } —— 编码：${list.functionCode }</option>
	            	</c:forEach>
			    	</select>
		    	</div> --%>
		    </li>
		    <li><label>功能項編碼：</label><input id="functionCode" name="functionCode" autocomplete="off" type="text" class="dfinput" /><i>*必填，長度須為1-6位</i></li>
		    <li><label>功能項路徑：</label><input id="functionUrl" name="functionUrl" autocomplete="off" type="text" class="dfinput" /><i>說明：僅三級功能項，需填寫此欄位，格式為：./*.do?action=****</i></li>
		    <li><label>備註：</label><input id="description" name="description" autocomplete="off" type="text" class="dfinput" /></li>
		    <li>
				<label>&nbsp;</label>
				<input name="" type="button" id="save" class="btn" value="確認保存"/> 
				<input style="margin-left:100px;" onclick="javascript:document.location.href = './adminFunction.do?action=list';" type="button" class="cancel" value="取消新增" />
			</li>
		    </ul>   
	    </form>
    </div>
</body>
</html>
